package com.app.aipass.fragment.main;

import android.app.Application;
import android.util.Log;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.app.aipass.app.AppApplication;
import com.app.aipass.app.Constants;
import com.app.aipass.data.DemoRepository;
import com.app.aipass.entity.AssetIndexEntity;
import com.app.aipass.entity.ConfigEntity;
import com.app.aipass.entity.FiveBuyFiveSellEntity;
import com.app.aipass.entity.GetAiIndexEntity;
import com.app.aipass.entity.PayAccountEntity;
import com.app.aipass.entity.PlanIndexEntity;
import com.app.aipass.entity.ShopTokenEntity;
import com.app.aipass.entity.UserEntity;
import com.app.aipass.entity.WalletEntity;
import com.app.aipass.http.response.ApiException;
import com.app.aipass.utils.ShareUtil;
import com.app.aipass.utils.SpUtils;
import com.app.aipass.utils.TextUtil;
import com.app.aipass.utils.ToastUtil;
import com.app.aipass.utils.Utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.observers.DisposableObserver;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;
import me.goldze.mvvmhabit.http.BaseResponse;
import me.goldze.mvvmhabit.http.ResponseThrowable;
import me.goldze.mvvmhabit.utils.RxUtils;
import me.goldze.mvvmhabit.utils.ToastUtils;
import okhttp3.ResponseBody;

/**
 * @author: woking
 * @date: 2021/6/15
 * @description：
 */
public class FundViewModel extends BaseViewModel<DemoRepository> {

    public SingleLiveEvent<Integer> type = new SingleLiveEvent<>();
    public SingleLiveEvent<Boolean> isOrder = new SingleLiveEvent<>();

    public SingleLiveEvent<GetAiIndexEntity> mGetAiIndexEntity = new SingleLiveEvent<>();
    public SingleLiveEvent<PlanIndexEntity> mPlanIndexEntity = new SingleLiveEvent<>();
    public SingleLiveEvent<AssetIndexEntity> mAssetIndexEntity = new SingleLiveEvent<>();//监听买卖按钮

    public SingleLiveEvent<ShopTokenEntity> mShopTokenEntity = new SingleLiveEvent<>();//监听买卖按钮

    public SingleLiveEvent<List<WalletEntity>> mWalletEntitys = new SingleLiveEvent<>();
    public SingleLiveEvent<List<PayAccountEntity>> mPayAccountEntitys = new SingleLiveEvent<>();//获取支付方式

    public SingleLiveEvent<List<FiveBuyFiveSellEntity>> mFiveBuyEntitys = new SingleLiveEvent<>();
    public SingleLiveEvent<List<FiveBuyFiveSellEntity>> mFiveSellEntitys = new SingleLiveEvent<>();
    public SingleLiveEvent<ConfigEntity> mConfigEntity = new SingleLiveEvent<>();
    public SingleLiveEvent<Boolean> otcPlanCreateBoolean = new SingleLiveEvent<>();

    //封装一个界面发生改变的观察者
    public UIChangeObservable uc = new UIChangeObservable();
    public class UIChangeObservable {
        //下拉刷新完成
        public SingleLiveEvent finishRefreshing = new SingleLiveEvent<>();
        //上拉加载完成
        public SingleLiveEvent finishLoadmore = new SingleLiveEvent<>();
    }

    public FundViewModel(@NonNull Application application, DemoRepository repository) {
        super(application, repository);
    }

    public void getAiIndex(){
        model.getAiIndex()
                .compose(RxUtils.schedulersTransformer()) //线程调度
                .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
                .doOnSubscribe(this)//请求与ViewModel周期同步
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Exception {
//                        showDialog("正在请求...");
                    }
                })
                .subscribe(new DisposableObserver<GetAiIndexEntity>() {

                    @Override
                    public void onNext(@NonNull GetAiIndexEntity getAiIndexEntity) {
                        if (getAiIndexEntity != null) {
                            mGetAiIndexEntity.postValue(getAiIndexEntity);
                        }

                    }

                    @Override
                    public void onError(@NonNull Throwable throwable) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void login()
    {
        HashMap<String, Object> map = new HashMap<>();
        map.put("mobile","");
        map.put("code","");
//        map.put("mobile","17124754566");
//        map.put("code","88888888");
        model.login(map)
                .compose(RxUtils.schedulersTransformer()) //线程调度
                .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
                .doOnSubscribe(this)//请求与ViewModel周期同步
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Exception {
//                        showDialog("正在请求...");
                    }
                })
                .subscribe(new DisposableObserver<BaseResponse<ShopTokenEntity>>() {
                    @Override
                    public void onNext(BaseResponse<ShopTokenEntity> response) {
                        Log.e("TAG",response.getCode()+"============login=====onNext========");
                        //请求成功
                        if (response != null && response.getData() != null) {
//                            Log.e("TAG","============getCSCToken======00000======="+response.getData().access_token);
                            mShopTokenEntity.postValue(response.getData());
//                            getCSCToken(response.getData().token_type + " " + response.getData().access_token);

                            ShareUtil.getInstance().save(ShareUtil.ACCESS_TOKEN,response.getData().token_type + " " + response.getData().access_token);
                            ShareUtil.getInstance().save(ShareUtil.ACCESS_TOKEN_VALUE,response.getData().access_token);
                        } else {
                            //code错误时也可以定义Observable回调到View层去处理
//                            ToastUtils.showShortSafe("数据错误");
                        }
                    }
                    @Override
                    public void onError(Throwable throwable) {
                        Log.e("TAG","============login=====onError========"+throwable.getMessage());
//                        if (throwable instanceof ResponseThrowable) {
//                            ToastUtils.showShortSafe(((ResponseThrowable) throwable).message);
//                        }
                    }
                    @Override
                    public void onComplete() {
                        Log.e("TAG","============login=====onComplete========");
                        apiConfigs();
                    }
                });
    }

    public void getZTXShopToken()
    {
        Log.e("TAG","============getZTXShopToken=============");
        UserEntity mUserEntity = ((AppApplication)AppApplication.getInstance()).getUserEntity();
        if(mUserEntity == null)
        {
            return;
        }
        model.getZTXShopToken(mUserEntity.mobile)
//        model.getCSCToken(token)
                .compose(RxUtils.schedulersTransformer()) //线程调度
                .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
                .doOnSubscribe(this)//请求与ViewModel周期同步
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Exception {
//                        showDialog("正在请求...");
                    }
                })
                .subscribe(new DisposableObserver<BaseResponse<ShopTokenEntity>>() {
                    @Override
                    public void onNext(BaseResponse<ShopTokenEntity> response) {
                        Log.e("TAG","============getZTXShopToken==========onNext===");
                        if(null != response && null != response.getData())
                        {
                            ShareUtil.getInstance().save(ShareUtil.ZTX_SHOP_TOKEN , response.getData().token_type+" " + response.getData().access_token);
                        }
                    }
                    @Override
                    public void onError(Throwable throwable) {
                        Log.e("TAG","============getZTXShopToken======onError======="+throwable.getMessage());
//                        if (throwable instanceof ResponseThrowable) {
//                            ToastUtils.showShortSafe(((ResponseThrowable) throwable).message);
//                        }
                    }
                    @Override
                    public void onComplete() {
                        Log.e("TAG","============getZTXShopToken=======onComplete======");
                    }
                });
    }

    //is_confirm=1 五买  is_confirm=0 五卖
    public void fiveBuy()
    {
        model.otcPlanOrders("1")
                .compose(RxUtils.schedulersTransformer()) //线程调度
                .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
                .doOnSubscribe(this)//请求与ViewModel周期同步
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Exception {
                        showDialog("正在请求...");
                    }
                })
                .subscribe(new DisposableObserver<BaseResponse<List<FiveBuyFiveSellEntity>>>() {
                    @Override
                    public void onNext(BaseResponse<List<FiveBuyFiveSellEntity>> response) {
                        Log.e("TAG","============fiveBuy=====onNext========");
                        if(null != response && null != response.getData() && response.getData().size() > 0)
                        {
                            mFiveBuyEntitys.setValue(response.getData());
                        }
                    }
                    @Override
                    public void onError(Throwable throwable) {
                        Log.e("TAG","============fiveBuy=====onError========");
                        dismissDialog();
                        fiveSell();
                    }
                    @Override
                    public void onComplete() {
                        Log.e("TAG","============fiveBuy=====onComplete========");
                        dismissDialog();
                        fiveSell();
                    }
                });
    }
    //is_confirm=1 五买  is_confirm=0 五卖
    public void fiveSell()
    {
        model.otcPlanOrders("0")
                .compose(RxUtils.schedulersTransformer()) //线程调度
                .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
                .doOnSubscribe(this)//请求与ViewModel周期同步
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Exception {
//                        showDialog("正在请求...");
                    }
                })
                .subscribe(new DisposableObserver<BaseResponse<List<FiveBuyFiveSellEntity>>>() {
                    @Override
                    public void onNext(BaseResponse<List<FiveBuyFiveSellEntity>> response) {
                        Log.e("TAG","============fiveSell=====onNext========");
                        if(null != response && null != response.getData() && response.getData().size() > 0)
                        {
                            mFiveSellEntitys.setValue(response.getData());
                        }
                    }
                    @Override
                    public void onError(Throwable throwable) {
                        Log.e("TAG","============fiveSell=====onError========");

                        otcWallet("");//钱包余额
                    }
                    @Override
                    public void onComplete() {
                        Log.e("TAG","============fiveSell=====onComplete========");
//                        dismissDialog();
                        otcWallet("");//钱包余额
                    }
                });
    }
    /**
     * 配置信息
     */
    public void apiConfigs()
    {
        model.apiConfigs()
                .compose(RxUtils.schedulersTransformer()) //线程调度
                .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
                .doOnSubscribe(this)//请求与ViewModel周期同步
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Exception {
                        showDialog("正在请求...");
                    }
                })
                .subscribe(new DisposableObserver<BaseResponse<ConfigEntity>>() {
                    @Override
                    public void onNext(BaseResponse<ConfigEntity> response) {
                        Log.e("TAG","============apiConfigs=====onNext========");
                        if(null != response && null != response.getData())
                        {
                            Constants.WEB_IMG_URL_UPLOADS = response.getData().url_image;
                            mConfigEntity.postValue(response.getData());

                            AppApplication.ad_level_exchange = response.getData().ad_level_exchange;
                        }
                    }
                    @Override
                    public void onError(Throwable throwable) {
                        Log.e("TAG","============apiConfigs=====onError========");
                        dismissDialog();
                        walletCoins();

//                        otcPlanData();//挂单数据
                    }
                    @Override
                    public void onComplete() {
                        Log.e("TAG","============apiConfigs=====onComplete========");
                        dismissDialog();
                        walletCoins();

//                        otcPlanData();//挂单数据
                    }
                });
    }

    /**
     * 钱包类型
     */
    public void walletCoins()
    {
        model.walletCoins()
                .compose(RxUtils.schedulersTransformer()) //线程调度
                .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
                .doOnSubscribe(this)//请求与ViewModel周期同步
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Exception {
//                        showDialog("正在请求...");
                    }
                })
                .subscribe(new DisposableObserver<Map<String,String>>() {
                    @Override
                    public void onNext(Map<String,String> response) {
                        Log.e("TAG","============walletCoins=====onNext========");
                        if(null != response)
                        {
//                            Log.e("TAG","============walletCoins=====onNext=====1111===");
                            if(response.size() > 0)
                            {
                                ((AppApplication)AppApplication.getInstance()).clearWalletCoins();
                                for (Map.Entry<String, String> entry : response.entrySet())
                                {
//                                    Log.e("TAG","============walletCoins=====onNext=====222222===Key = " + entry.getKey() + ", Value = " + entry.getValue());
                                    ((AppApplication)AppApplication.getInstance()).addWalletCoins(entry.getValue(),entry.getKey());
                                }
                            }
                        }
                    }
                    @Override
                    public void onError(Throwable throwable) {
                        Log.e("TAG","============walletCoins=====onError========"+throwable.getMessage());
                        if (throwable instanceof ResponseThrowable) {
                            String msg = ApiException.getShowmessage(((ResponseThrowable) throwable).errorBody);
                            int code = ((ResponseThrowable) throwable).code;
                            if((!TextUtil.isEmpty(msg) && msg.contains("被禁")) || code == 403)
                            {
                                if(TextUtil.isEmpty(AppApplication.userJinYongMsg))
                                {
                                    AppApplication.userJinYongMsg = msg;
                                }
                            }
                            else
                            {
                                if(!TextUtil.isEmpty(AppApplication.userJinYongMsg))
                                {
                                    AppApplication.userJinYongMsg = "";
                                }
                            }
                            ToastUtils.showShortSafe(msg);
                        }
//                        dismissDialog();

                        otcPlanData();//挂单数据

//                        baseUser();
                    }
                    @Override
                    public void onComplete() {
                        Log.e("TAG","============walletCoins=====onComplete========");
//                        dismissDialog();
                        if(!TextUtil.isEmpty(AppApplication.userJinYongMsg))
                        {
                            AppApplication.userJinYongMsg = "";
                        }
                        otcPlanData();//挂单数据

//                        baseUser();
                    }
                });
    }

    /**
     * 挂单数据  参考价格
     */
    public void otcPlanData()
    {
        model.otcPlanData()
                .compose(RxUtils.schedulersTransformer()) //线程调度
                .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
                .doOnSubscribe(this)//请求与ViewModel周期同步
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Exception {
//                        showDialog("正在请求...");
                    }
                })
                .subscribe(new DisposableObserver<PlanIndexEntity>() {
                    @Override
                    public void onNext(PlanIndexEntity response) {
                        Log.e("TAG","============otcPlanData=====onNext========");
                        if(null != response)
                        {
                            Log.e("TAG","============otcPlanData=====onNext===11111=====");
                            mPlanIndexEntity.setValue(response);
                        }
                    }
                    @Override
                    public void onError(Throwable throwable) {
                        Log.e("TAG","============otcPlanData=====onError========");
//                        if (throwable instanceof ResponseThrowable) {
//                            ToastUtils.showShortSafe(((ResponseThrowable) throwable).message);
//                        }
//                        dismissDialog();
                        fiveBuy();
                    }
                    @Override
                    public void onComplete() {
                        Log.e("TAG","============otcPlanData=====onComplete========");
//                        dismissDialog();
                        fiveBuy();
                    }
                });
    }

    /**
     * 挂单创建
     */
    public void otcPlanCreate(HashMap<String, Object> map)
    {
//        HashMap<String, Object> map = new HashMap<>();
//        String type = "1";
//        map.put("type","1");//类型:1=购买,2=出售
//        map.put("num","1");//挂单数量
//        map.put("pay_types ","1");//支付方式: 1,2,3
//        map.put("price  ","13.2");//价格
//        if(type.equals("2") || type.equals("3"))
//        {
//            map.put("idcard ","123456");//身份证尾号6位,如果type=2必填
//            map.put("code  ","88888888");//短信码, 如果type=2必填
//        }
        model.otcPlanCreate(map)
                .compose(RxUtils.schedulersTransformer()) //线程调度
                .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
                .doOnSubscribe(this)//请求与ViewModel周期同步
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Exception {
                        showDialog("正在请求...");
                    }
                })
                .subscribe(new DisposableObserver<ResponseBody>() {
                    @Override
                    public void onNext(ResponseBody response) {
                        Log.e("TAG","============otcPlanCreate=====onNext========");
//                        if(null != response && null != response.getData())
//                        {
////                            mPlanIndexEntity.setValue(response.getData());
//                        }
                        otcPlanCreateBoolean.postValue(true);
                    }
                    @Override
                    public void onError(Throwable throwable) {
                        Log.e("TAG",throwable.toString()+"============otcPlanCreate=====onError========"+throwable.getMessage());
                        dismissDialog();
                        if (throwable instanceof ResponseThrowable) {
//                            Log.e("TAG","============otcPlanCreate=====onError====123===="+((ResponseThrowable) throwable).errorBody);
                            ToastUtils.showShortSafe(ApiException.getShowmessage(((ResponseThrowable) throwable).errorBody));
                        }
                    }
                    @Override
                    public void onComplete() {
                        dismissDialog();
                        ToastUtils.showShortSafe("提交成功");
                        Log.e("TAG","============otcPlanCreate=====onComplete========");
                    }
                });
    }

    /**
     * 短信验证码
     */
    public void smsCode(TextView send_yzm_tv)
    {
        UserEntity mUserEntity = ((AppApplication)AppApplication.getInstance()).getUserEntity();
        if(mUserEntity == null)
        {
            ToastUtil.showToast("手机号为空");
            return;
        }
        //type:手机验证码类型：1:注册，2:找回密码，3:更换手机号, 4:添加银行卡, 5:设置支付密码,6: 登陆, 11: otc支付, 12: 挂单 用户, 13:挂单 订单
        HashMap<String, Object> map = new HashMap<>();
        map.put("type","12");//类型:1=购买,2=出售
        map.put("phone",((AppApplication)AppApplication.getInstance()).getUserEntity().mobile);//挂单数量

        model.smsCode(map)
                .compose(RxUtils.schedulersTransformer()) //线程调度
                .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
                .doOnSubscribe(this)//请求与ViewModel周期同步
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Exception {
//                        showDialog("正在请求...");
                    }
                })
                .subscribe(new DisposableObserver<ResponseBody>() {
                    @Override
                    public void onNext(ResponseBody response) {
                        Log.e("TAG","============smsCode=====onNext========");
                        if(null != response)
                        {
//                            mPlanIndexEntity.setValue(response.getData());
                        }
                    }
                    @Override
                    public void onError(Throwable throwable) {
                        Log.e("TAG","============smsCode=====onError========");
                        if (throwable instanceof ResponseThrowable) {
                            ToastUtils.showShortSafe(((ResponseThrowable) throwable).message);
                        }
                    }
                    @Override
                    public void onComplete() {
                        Log.e("TAG","============smsCode=====onComplete========");
                        ToastUtils.showShortSafe("发送成功");
                        send_yzm_tv.setEnabled(false);
//                        send_yzm_tv.setBackgroundResource(R.drawable.shape_d9dade_50);
                        Utils.showCount(send_yzm_tv);
                    }
                });
    }
    public void baseUser() {
        Log.e("TAG","==========baseUser=============");
        model.baseUser()
                .compose(RxUtils.schedulersTransformer()) //线程调度
                .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
                .doOnSubscribe(this)//请求与ViewModel周期同步
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Exception {
                        showDialog("正在请求...");
                    }
                })
                .subscribe(new DisposableObserver<BaseResponse<UserEntity>>() {
                    @Override
                    public void onNext(BaseResponse<UserEntity> response) {
                        Log.e("TAG","================baseUser===onNext====");
                        if(null != response && null != response.getData())
                        {
                            ((AppApplication)AppApplication.getInstance()).setUserEntity(response.getData());
                            SpUtils.put(AppApplication.getInstance().getApplicationContext(), "authentication", response.getData().authentication);
                            AppApplication.ad_exchange_level = response.getData().ad_exchange_level;
                        }
                    }
                    @Override
                    public void onError(Throwable throwable) {
                        Log.e("TAG","================baseUser===onError===="+throwable.getMessage());
                        dismissDialog();
                        //请求刷新完成收回
                        uc.finishRefreshing.call();
                        getZTXShopToken();
//                        otcPlanData();//挂单数据
                    }
                    @Override
                    public void onComplete() {
                        Log.e("TAG","================baseUser===onComplete====");
                        dismissDialog();
                        //请求刷新完成收回
                        uc.finishRefreshing.call();
                        getZTXShopToken();
//                        otcPlanData();//挂单数据
                    }
                });
    }

    /**
     * 钱包余额
     */
    public void otcWallet(String include)
    {
        model.otcWallet("coin")
                .compose(RxUtils.schedulersTransformer()) //线程调度
                .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
                .doOnSubscribe(this)//请求与ViewModel周期同步
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Exception {
                        if(TextUtil.isEmpty(include))
                        {
                            showDialog("正在请求...");
                        }
                    }
                })
                .subscribe(new DisposableObserver<BaseResponse<List<WalletEntity>>>() {
                    @Override
                    public void onNext(BaseResponse<List<WalletEntity>> response) {
                        if(response != null && response.getData() != null && response.getData().size() > 0)
                        {
                            Log.e("TAG","============otcWallet=====onNext========"+response.getData().size());
                            mWalletEntitys.postValue(response.getData());
                            ((AppApplication)AppApplication.getInstance()).setOtcWalletAll(response.getData());
                        }
                    }
                    @Override
                    public void onError(Throwable throwable) {
                        Log.e("TAG","============otcWallet=====onError========");
//                        if (throwable instanceof ResponseThrowable) {
//                            ToastUtils.showShortSafe(((ResponseThrowable) throwable).message);
//                        }
                        if(TextUtil.isEmpty(include))
                        {
                            dismissDialog();
                        }
//                        //请求刷新完成收回
//                        uc.finishRefreshing.call();

                        baseUser();
                    }
                    @Override
                    public void onComplete() {
                        Log.e("TAG","============otcWallet=====onComplete========");
                        if(TextUtil.isEmpty(include))
                        {
                            dismissDialog();
                        }
//                        //请求刷新完成收回
//                        uc.finishRefreshing.call();
                        baseUser();
                    }
                });
    }
    /**
     * 钱包余额
     */
    public void otcWalletFund(String include)
    {
        model.otcWallet("coin")
                .compose(RxUtils.schedulersTransformer()) //线程调度
                .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
                .doOnSubscribe(this)//请求与ViewModel周期同步
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Exception {
                        if(TextUtil.isEmpty(include))
                        {
                            showDialog("正在请求...");
                        }
                    }
                })
                .subscribe(new DisposableObserver<BaseResponse<List<WalletEntity>>>() {
                    @Override
                    public void onNext(BaseResponse<List<WalletEntity>> response) {
                        if(response != null && response.getData() != null && response.getData().size() > 0)
                        {
                            Log.e("TAG","============otcWallet=====onNext========"+response.getData().size());
                            mWalletEntitys.postValue(response.getData());
                            ((AppApplication)AppApplication.getInstance()).setOtcWalletAll(response.getData());
                        }
                    }
                    @Override
                    public void onError(Throwable throwable) {
                        Log.e("TAG","============otcWallet=====onError========");
//                        if (throwable instanceof ResponseThrowable) {
//                            ToastUtils.showShortSafe(((ResponseThrowable) throwable).message);
//                        }
                        //请求刷新完成收回
                        uc.finishRefreshing.call();
                        if(TextUtil.isEmpty(include))
                        {
                            dismissDialog();
                        }

                        String token = ShareUtil.getInstance().getString(ShareUtil.ZTX_SHOP_TOKEN,"").trim();
                        if(TextUtil.isEmpty(token) || token.length() < 1)
                        {
                            baseUser();
                        }
                    }
                    @Override
                    public void onComplete() {
                        Log.e("TAG","============otcWallet=====onComplete========");
                        //请求刷新完成收回
                        uc.finishRefreshing.call();
                        if(TextUtil.isEmpty(include))
                        {
                            dismissDialog();
                        }
                        String token = ShareUtil.getInstance().getString(ShareUtil.ZTX_SHOP_TOKEN,"").trim();
                        if(TextUtil.isEmpty(token) || token.length() < 1)
                        {
                            baseUser();
                        }
                    }
                });
    }

    public void otcPayCccount() {
        Log.e("TAG","==========otcPayCccount=============");

        model.otcPayCccount()
                .compose(RxUtils.schedulersTransformer()) //线程调度
                .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
                .doOnSubscribe(this)//请求与ViewModel周期同步
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Exception {
                        showDialog("正在请求...");
                    }
                })
                .subscribe(new DisposableObserver<BaseResponse<List<PayAccountEntity>>>() {
                    @Override
                    public void onNext(BaseResponse<List<PayAccountEntity>> response) {
                        Log.e("TAG","==========otcPayCccount=======onNext======");
//                        dismissDialog();
                        //请求成功
                        if (response != null && null != response.getData() && response.getData().size() > 0) {
                            mPayAccountEntitys.postValue(response.getData());
                        }
                        else
                        {
                            ToastUtil.showToast("请添加收款方式");
                        }
                    }
                    @Override
                    public void onError(Throwable throwable) {
                        Log.e("TAG","==========otcPayCccount=========onError====");
                        //关闭对话框
                        dismissDialog();
                        if (throwable instanceof ResponseThrowable) {
                            ToastUtils.showShortSafe(((ResponseThrowable) throwable).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        Log.e("TAG","==========otcPayCccount=====onComplete========");
                        //关闭对话框
                        dismissDialog();
                    }
                });
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}